package com.haliyoo.adhs.common;

import java.lang.reflect.Type;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.haliyoo.adhs.model.AdInfo;
import com.haliyoo.adhs.model.User;

public class JSONUtils {
	
	public static Type UserType = new TypeToken<ResultData<User>>() {}.getType();
	public static Type StringType = new TypeToken<ResultData<String>>() {}.getType();
	public static Type IntegerType = new TypeToken<ResultData<Integer>>() {}.getType();
	public static Type AdInfoType = new TypeToken<ResultData<AdInfo>>() {}.getType();
	
	public static <T> String toJson(Object o,Type type){
		GsonBuilder builder = new GsonBuilder(); 
		builder.setDateFormat("yyyy-MM-dd HH:mm:ss");
		Gson gson = builder.create();
		return gson.toJson(o,type);
	}
	
	public static <T> Object fromJson(String json,Type type){
		Gson gson = new Gson();
		return gson.fromJson(json, type);
	}	
}
